#include <gtk/gtk.h>

/*gboolean ok_handler(GtkWidget *window, GdkEventKey *event,
					 gpointer data)
{
	GtkWidget *d;

	d = gtk_message_dialog_new (GTK_WINDOW(window),
			GTK_DIALOG_DESTROY_WITH_PARENT,
			GTK_MESSAGE_INFO,
			GTK_BUTTONS_OK,
			"data %s", data);

	return TRUE;
}*/

gboolean cancel_handler(GtkWidget *btn, GdkEventKey *event,
		gpointer data)
{
	gtk_widget_destroy(data);
	printf("Quitting....");

	//gtk_main_quit();

	return FALSE;
}

int main(int argc, char *argv[])
{
	GtkWidget *window;
	GtkWidget *btn_ok, *btn_cancel;
	GtkWidget *lbl_title, *lbl_name;
	GtkWidget *txt_name;
	GtkWidget *vbox, *hbox1, *hbox2, *hbox3;
	gtk_init(&argc, &argv);

	// Start the window
	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	vbox = gtk_vbox_new(FALSE, 0);
	gtk_widget_show(vbox);
	gtk_container_add(window, vbox);
	gtk_widget_show(window);

	// Build the title
	lbl_title = gtk_label_new("Simple widget");
	gtk_widget_show(lbl_title);
	gtk_container_add(vbox, lbl_title);

	// The text entry
	lbl_name = gtk_label_new("Name: ");
	gtk_widget_show(lbl_name);
	txt_name = gtk_entry_new();
	gtk_widget_show(txt_name);
	hbox1 = gtk_hbox_new(FALSE, 0);
	gtk_widget_show(hbox1);
	gtk_container_add(hbox1, lbl_name);
	gtk_container_add(hbox1, txt_name);
	gtk_container_add(vbox, hbox1);

	// The buttons row
	hbox2 = gtk_hbox_new(FALSE, 0);
	btn_cancel = gtk_button_new_with_label("Cancel");
	gtk_widget_show(btn_cancel);
	btn_ok = gtk_button_new_with_label("OK");
	gtk_widget_show(btn_ok);
	gtk_container_add(hbox2, btn_cancel);
	gtk_container_add(hbox2, btn_ok);
	gtk_container_add(vbox, hbox2);
	gtk_widget_show(hbox2);
	GtkWidget *bfr = gtk_entry_get_buffer(txt_name);
	gchar *str = gtk_entry_buffer_get_text(bfr);
	// Register event handler for
	/*g_signal_connect(G_OBJECT(window), "clicked",
			G_CALLBACK(ok_handler), str);*/
	GtkWidget *g;
	g = gtk_message_dialog_new(window,
            GTK_DIALOG_DESTROY_WITH_PARENT,
            GTK_MESSAGE_INFO,
            GTK_BUTTONS_OK,
            "Your first dialog, huh!");
	gtk_dialog_run(g);
	g_signal_connect(G_OBJECT(btn_cancel), "clicked",
			G_CALLBACK(cancel_handler) ,window);

	gtk_main();

	return 0;
}
